// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   LIST_CRAdapterImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CR;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.LIST_CR;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.Iterator;
import java.util.List;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            LISTAdapterCommonImpl, ANYImpl, BLImpl, CRImpl, 
//            CSImpl, NullFlavorImpl, TYPEImpl

public class LIST_CRAdapterImpl extends LISTAdapterCommonImpl
    implements LIST_CR
{

    public static final String RCS_ID = "$Header: LIST_CRAdapterImpl.java 115.19 2005/09/16 09:23:52 amchanda noship $";
    private static final LIST_CR nullNI = new LIST_CRAdapterImpl(CSImpl.valueOf("NI"));
    private static final LIST_CR nullOTH = new LIST_CRAdapterImpl(CSImpl.valueOf("OTH"));
    private static final LIST_CR nullNINF = new LIST_CRAdapterImpl(CSImpl.valueOf("NINF"));
    private static final LIST_CR nullPINF = new LIST_CRAdapterImpl(CSImpl.valueOf("PINF"));
    private static final LIST_CR nullUNK = new LIST_CRAdapterImpl(CSImpl.valueOf("UNK"));
    private static final LIST_CR nullASKU = new LIST_CRAdapterImpl(CSImpl.valueOf("ASKU"));
    private static final LIST_CR nullNAV = new LIST_CRAdapterImpl(CSImpl.valueOf("NAV"));
    private static final LIST_CR nullMSK = new LIST_CRAdapterImpl(CSImpl.valueOf("MSK"));
    private static final LIST_CR nullNA = new LIST_CRAdapterImpl(CSImpl.valueOf("NA"));
    private static final LIST_CR nullNASK = new LIST_CRAdapterImpl(CSImpl.valueOf("NASK"));

    public LIST_CRAdapterImpl(CS cs)
    {
        super(cs);
    }

    public LIST_CRAdapterImpl(List list)
    {
        super(list);
    }

    public CR head()
    {
        if(isNull().isTrue())
            return CRImpl.nullCR(NullFlavorImpl.NI);
        CR cr = null;
        try
        {
            cr = (CR)mList.get(0);
        }
        catch(IndexOutOfBoundsException _ex)
        {
            return CRImpl.nullCR(NullFlavorImpl.NI);
        }
        return cr;
    }

    public LIST_CR tail()
    {
        if(isNull().isTrue())
            return nullLIST_CR(NullFlavorImpl.NI);
        LIST_CRAdapterImpl list_cradapterimpl = null;
        try
        {
            List list = mList.subList(1, mList.size());
            list_cradapterimpl = new LIST_CRAdapterImpl(list);
        }
        catch(IllegalArgumentException _ex)
        {
            return nullLIST_CR(NullFlavorImpl.NI);
        }
        return list_cradapterimpl;
    }

    public CR item(INT int1)
    {
        if(isNull().isTrue())
            return CRImpl.nullCR(NullFlavorImpl.NI);
        CR cr = null;
        try
        {
            cr = (CR)mList.get(int1.intValue());
        }
        catch(IndexOutOfBoundsException _ex)
        {
            return CRImpl.nullCR(NullFlavorImpl.NI);
        }
        return cr;
    }

    public BL contains(CR cr)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL(NullFlavorImpl.NI);
        else
            return BLImpl.valueOf(mList.contains(cr));
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.LIST_CR;
    }

    public BL equal(ANY any)
    {
        if(any instanceof LIST_CR)
        {
            if(isNull().or(any.isNull()).isTrue())
                return BLImpl.FALSE;
            LIST_CR list_cr = (LIST_CR)any;
            Iterator iterator = listIterator();
            Iterator iterator1;
            for(iterator1 = list_cr.listIterator(); iterator.hasNext() && iterator1.hasNext();)
                if(!((CR)iterator.next()).equal((CR)iterator1.next()).isTrue())
                    return BLImpl.FALSE;

            if(iterator.hasNext() || iterator1.hasNext())
                return BLImpl.FALSE;
            else
                return BLImpl.TRUE;
        } else
        {
            return BLImpl.FALSE;
        }
    }

    public static LIST_CR valueOf(List list)
    {
        return new LIST_CRAdapterImpl(list);
    }

    public static LIST_CR nullLIST_CR()
    {
        return new LIST_CRAdapterImpl(((CS) (null)));
    }

    public Iterator listIterator()
    {
        if(mList == null)
            return null;
        else
            return mList.listIterator();
    }

    protected boolean verifyItem(Object obj)
    {
        return obj instanceof CR;
    }

    public static LIST_CR nullLIST_CR(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
